﻿using System;
using LinQProject;
using ServiceProject.EntityService;


public partial class controls_ucClientInfo : System.Web.UI.UserControl
{
    
    protected ClientService clientService=new ClientService(database);
    private static FarmacieDataClassesDataContext database = new FarmacieDataClassesDataContext();

    public string UserId
    {
        get
        {
            if (String.IsNullOrEmpty(hdnUserID.Value))
                return string.Empty;
            return hdnUserID.Value;
        }
        set
        {
            hdnUserID.Value=value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            LoadClient();
    }

    public void LoadClient()
    {
        if (!String.IsNullOrEmpty(UserId))
        {
            Guid userGuid=new Guid(UserId);
            Client cl=clientService.GetClientByUser(null, userGuid);
            if (cl == null)
                SetNoClient();
            else
                SetClient(cl);
        }
        else
            SetNoClient();
    }

    private void SetClient(Client cl)
    {
        lblName.Text = cl.ClientName;
        lblJudet.Text = cl.Region.RegionName;
        lblLocalitate.Text = cl.City;
        SetVisibility(true);
    }

    private void SetNoClient()
    {
        lblName.Text = string.Empty;
        lblJudet.Text = string.Empty;
        lblLocalitate.Text = string.Empty;

        SetVisibility(false);
    }

    private void SetVisibility(bool isVisible)
    {
        lblName.Visible = isVisible;
        lblJudet.Visible = isVisible;
        lblLocalitate.Visible = isVisible;

        //lblDisplayJudet.Visible = isVisible;
        //lblDisplayLocalitate.Visible = isVisible;
        //lblDisplayName.Visible = isVisible;
    }
}
